package com.simple.mqtt.common.domain;

import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@RequiredArgsConstructor
public class TopicFilter {

    /**
     * topicFilter
     */
    private final String topic;
    /**
     * topicFilterType
     */
    private final TopicFilterType type;

    public TopicFilter(String topicFilter) {
        this.topic = topicFilter;
        this.type = TopicFilterType.getType(topicFilter);
    }

    /**
     * 判断 topicFilter 和 topicName 匹配情况
     *
     * @param topicName topicName
     * @return 是否匹配
     */
    public boolean match(String topicName) {
        return type.match(this.topic, topicName);
    }
}